#include "addstudent.h"
#include "ui_addstudent.h"
#include "addperson.h"
#include "mainwindow.h"
#include <QMessageBox>
#include <vector>
#include <teacher.h>
#include <student.h>
#include <fstream>
#include "bigsave.h"
extern vector<Teacher*> tdata;
extern vector<student*> sdata;
addstudent::addstudent(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::addstudent)
{
    ui->setupUi(this);
}

addstudent::~addstudent()
{
    delete ui;
}

void addstudent::on_pushButton_2_clicked()
{
    this->close();
    addperson*p=new(addperson);
    p->show();
}

void addstudent::on_pushButton_clicked()
{
    QString str1,str2,str3,str4,str5,str6,str7,str8;
    str1=ui->lineEdit->text();
    str2=ui->lineEdit_2->text();
    str3=ui->lineEdit_3->text();
    str4=ui->lineEdit_4->text();
    str5=ui->lineEdit_5->text();
    str6=ui->lineEdit_6->text();
    str7=ui->lineEdit_7->text();
    str8=ui->lineEdit_8->text();
    if(str1==""||str2==""||str3==""||str4==""||str5==""||str6==""||str7==""||str8==""||(ui->radioButton==0&&ui->radioButton_2==0)){
    QMessageBox::critical(this,"错误","请输入完整信息");
    }
    else{
        int r=0;
        for(unsigned int i=0;i<tdata.size();i++)
        {
            if(tdata[i]->ifhave(str1))
            {
                r=1;
            }
        }
        for(unsigned int i=0;i<sdata.size();i++)
        {
            if(sdata[i]->ifhave(str1))
            {
                r=1;
            }
        }
        if(r==1){
        QMessageBox::information(this,"提示","此用户名已存在");
        }
    else{
    ofstream outfile;
    outfile.open("C:/sr_system/Zload.txt",iostream::app);
    outfile<<str1.toStdString()<<endl<<str2.toStdString()<<endl;
    sdata.push_back(new student(str1,str3,ui->radioButton->isChecked(),str4.toInt(),str8,str5,str7,str6,0,0));
    QMessageBox::information(this,"成功","添加信息成功");
    bigsave();
    }
    }
}
